package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.thread.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IMemberReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private IMemberReservationService memberReservationService;
    /**
     * 查询取消预约数量
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Integer count = memberReservationService.getCancelledReservationCount();
        return R.ok(count);
    }
    /**
     * 取消预约
     */
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public R cancelReservation(@PathVariable Long id) {
        memberReservationService.cancelReservation(id);
        return R.ok();
    }

    /**
     * 分页查询预约信息
     */
    @GetMapping("/page")
    @ApiOperation("分页查询预约信息")
    public TableDataInfo<List<Reservation>>  page(Integer pageNum, Integer pageSize,Integer  status ){
        startPage();
        List<Reservation> list = memberReservationService.selectByPage(status);
        return getDataTable(list);
    }
    /**
     * 添加预约信息
     */
    @PostMapping
    @ApiOperation("添加预约信息")
    public R add(@RequestBody Reservation reservation) {
        memberReservationService.add(reservation);
        return R.ok();
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询指定时间段预约数量")
    public R<Integer> countByTime( Long time) {
        Integer count = memberReservationService.countByTime(time);
        return R.ok(count);
    }





}